package com.socialuni.sdk.domain;

import com.socialuni.sdk.factory.CommentFactory;
import com.socialuni.sdk.manage.talk.TalkManage;
import com.socialuni.sdk.model.DO.comment.CommentDO;
import com.socialuni.sdk.model.DO.talk.TalkDO;
import com.socialuni.sdk.model.QO.comment.CommentAddVO;
import com.socialuni.sdk.repository.CommentRepository;
import com.socialuni.sdk.repository.TalkRepository;
import com.socialuni.sdk.service.ReportService;
import com.socialuni.sdk.service.comment.CommentAddLineTransfer;
import com.socialuni.sdk.service.comment.CommentCheckService;
import com.socialuni.sdk.store.CommentStore;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CommentDomain {
    @Resource
    private CommentRepository commentRepository;
    @Resource
    private CommentStore commentStore;

    @Resource
    private TalkManage talkManage;

    @Resource
    private ReportService reportService;

    @Resource
    private CommentCheckService commentCheckService;
    @Resource
    private CommentDomain commentDomain;
    @Resource
    private NotifyDomain notifyDomain;

    @Resource
    private CommentFactory commentFactory;

    @Resource
    private TalkRepository talkRepository;

    public CommentAddLineTransfer saveComment(CommentAddVO addVO, CommentAddLineTransfer commentAddLineTransfer, Integer requestUserId, String threeUnionId) {
        //创建和保存comment到db
        CommentDO commentDO = commentStore.saveAddComment(addVO, requestUserId,  threeUnionId);

        //关联更新talk到db，时间、评论次数等
        TalkDO talkDO = talkManage.updateTalkByAddComment(commentAddLineTransfer.getTalk());
        //设置为更新后的talk
        commentAddLineTransfer.setTalk(talkDO);
        //关联更新comment到db，时间、评论次数等
        commentAddLineTransfer = commentStore.updateCommentByAddComment(commentAddLineTransfer);

        commentAddLineTransfer.setCommentDO(commentDO);

        return commentAddLineTransfer;
    }
}
